package com.acc.service.impl;

import java.util.List;

import com.acc.dao.RoleUriDAO;
import com.acc.dao.impl.RoleUriDAOImpl;
import com.acc.entity.AdminRole;
import com.acc.entity.RoleUri;
import com.acc.service.RoleUriService;
/**
 * 
 * @author 朱春阳
 *
 */
public class RoleUriServiceImpl implements RoleUriService{

	private RoleUriDAO roleuridao = new RoleUriDAOImpl(); 
	/**
	 * 分页
	 */
	@Override
	public List<RoleUri> getPageRoleUri(String roleName, Integer page, Integer size) {
		// TODO Auto-generated method stub
		String sql = "select * from (select t.*, rownum num from (select ti_role.* from ti_role where role=?) t where rownum <= ?) p where p.num > ?";
		
		List<RoleUri> list = roleuridao.getAllRoleUri(sql, roleName,  page * size, (page-1)*size);
	
		return list;
	}

	/**
	 * 删除
	 */
	@Override
	public boolean deleteRoleUri(Integer id) {
		// TODO Auto-generated method stub
		String sql = "delete from ti_role where role_id=?";
		Integer num = roleuridao.updateOneRoleUri(sql, id);
		if(num != null) {
			return true;
		}else {
			return false;
		}
	}

	/**
	 * 新增
	 */
	@Override
	public boolean addRoleUri(RoleUri roleuri) {
		// TODO Auto-generated method stub
		String sql = "insert into ti_role values(seq_role_id.nextval ,?,?)";
		Integer num = roleuridao.updateOneRoleUri(sql, roleuri.getRole(), roleuri.getUri());
		return (num != null);
	}

	/**
	 * 修改
	 */
	@Override
	public boolean updateRoleUri(String adminName, String adminRole, Integer id) {
		// TODO Auto-generated method stub
		String sql = "update ti_role set role = ? and uri = ? where id=?";
		Integer num = roleuridao.updateOneRoleUri(sql, adminName, adminRole, id);
		return num != null;
	}

	@Override
	public Integer getAll() {
		// TODO Auto-generated method stub
		String sql = "select * from ti_role";
		List<RoleUri> list = roleuridao.getAllRoleUri(sql);
		return list.size();
	}

	@Override
	public Integer getAllById(String roleName) {
		// TODO Auto-generated method stub
		List<RoleUri> roleuri = roleuridao.getAllRU(roleName); 
		return roleuri.size();
	}

	@Override
	public Integer getAllByName(String roleName) {
		// TODO Auto-generated method stub
		List<RoleUri> roleuri = roleuridao.getAllRUByName(roleName);
		return roleuri.size();
	}

	@Override
	public List<RoleUri> getPage(Integer page, Integer rows) {
		// TODO Auto-generated method stub
		List<RoleUri> roleuri = roleuridao.getAllPgae(page*rows, (page-1)*rows); 
		return roleuri;
	}

}
